Shader "Custom/卡通"
{
	Properties
	{
		_Color("Color", Color) = (1, 1, 1, 1)
		_HColor("Highlight Color", Color) = (0.8, 0.8, 0.8, 1.0)
		_SColor("Shadow Color", Color) = (0.2, 0.2, 0.2, 1.0)
		_MainTex("Main Texture", 2D) = "white" {}
		_RampThreshold("Ramp Threshold", Range(0, 1)) = 0.5
		_RampSmooth("Ramp Smooth", Range(0, 1)) = 0.1
		_OutlineColor("Outline Color", Color) = (0, 0, 0, 1)
		_OutlineWidth("Outline Width", Float) = 0.05
		_Brightness("Brightness", Range(1.0, 2.0)) = 1.2
		_HeightLightFactor("Height Light Factor", Range(0.0, 10.0)) = 2.0
		_HeightMin("Height Min", Float) = 0.0 
		_HeightMax("Height Max", Float) = 5.0 
	}

	SubShader
	{
		Tags { "RenderType" = "Opaque"}
	    LOD 100

        CGPROGRAM
       #pragma surface surf Lambert

        sampler2D _MainTex;
        fixed4 _Color;
        fixed4 _HColor;
        fixed4 _SColor;
        float _RampThreshold;
        float _RampSmooth;
        float _Brightness;
        float _HeightLightFactor; 
        float _HeightMin; 
        float _HeightMax; 

        struct Input
        {
            float2 uv_MainTex;
            float3 worldNormal;
            float3 worldPos;
        };

        void vert(inout appdata_full v, out Input o)
        {
            UNITY_INITIALIZE_OUTPUT(Input, o);
            o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
            o.worldNormal = UnityObjectToWorldNormal(v.normal);
        }

        void surf(Input IN, inout SurfaceOutput o)
        {
            fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
            fixed3 lightDir = normalize(UnityWorldSpaceLightDir(IN.worldNormal));
            float ndotl = dot(IN.worldNormal, lightDir);

            float rampFactor = smoothstep(_RampThreshold - _RampSmooth, _RampThreshold + _RampSmooth, ndotl);

            float heightFactor = smoothstep(_HeightMin, _HeightMax, IN.worldPos.y) * _HeightLightFactor;

            fixed3 color = lerp(_SColor.rgb, _HColor.rgb, rampFactor + heightFactor);
            o.Albedo = (tex.rgb * _Color.rgb * color) * _Brightness;
            o.Alpha = tex.a;
        }

        ENDCG
	}
    FallBack "Diffuse"
}
